package com.nulldev.util.io.nfs.demo;

import java.util.Map.Entry;

import com.nulldev.util.io.FileUtil;
import com.nulldev.util.io.nfs.nFile;
import com.nulldev.util.io.nfs.nFileSystem;
import com.nulldev.util.java.JVMUtil;

public class nFSDemo {

	public static void main(String[] args) throws Exception {
		//final nFileSystem nfs = new nFileSystem(FileUtil.safeCreate("[redacted]"));
		//final nFile demoFile = new nFile("test.txt", "Hello world!".getBytes());
		//nfs.addFile(demoFile);
		//nfs.__print_files();
		//nfs.toFile(FileUtil.safeCreate("[redacted]"));
		final boolean read = true;
		if (read) {
			final nFileSystem nfs = new nFileSystem(FileUtil.safeCreate("[redacted]"));
			nfs.__print_files();
			//final nFile f = nfs.getFile("test.txt");
			//JVMUtil.async_println("Metadata: " + new String(f.getMetadataBytes()));
			//JVMUtil.async_println("");
			//JVMUtil.async_println(new String(f.getData()));
			JVMUtil.async_println("Printing contents and metadata of each file...");
			for (final Entry<String, nFile> entries : nfs.entrySet()) {
				JVMUtil.async_println(new String(entries.getValue().getMetadataBytes()));
				JVMUtil.async_println(new String(entries.getValue().getData()));
			}
		}else {
			final nFileSystem nfs = new nFileSystem();
			final nFile demoFile = new nFile("test.txt", "Hello world!".getBytes());
			nfs.addFile(demoFile);
			final nFile demoFile2 = new nFile("test2.test", "Hello too!".getBytes());
			nfs.addFile(demoFile2);
			nfs.__print_files();
			nfs.toFile(FileUtil.safeCreate("[redacted]"));
		}
	}

}
